<!--  -->
<template>
  <div class="comment">
    <!-- <h1>累计评价</h1> -->
    <div class="comment-grade">
      <el-tabs v-model="activeName" @tab-click="handleClick" type="border-card">
        <el-tab-pane label="全部" name="first"> <div class="comment-detail" >
      <ul>
        <li v-for="item in commentInfo" :key="item.id">
          <section class="comment-section" >
            <div class="section-right">
               <img :alt="item.username" :src="item.header">
              <div>{{item.username}}</div>
            </div> 
            <div class="section-left">
             <div class="section-comment">{{item.description}}</div>
              <div class="section-time">评价时间: {{item.createTime | dateFormat}}  &nbsp;&nbsp;&nbsp;  &nbsp;&nbsp;&nbsp; 商品名:  <span class="spuName">{{item.spuName}}&nbsp;&nbsp;</span>商品属性: <span class="spuName">{{item.skuValues}}</span></div>
              <div class="section-count" @click="addGoods(item)"> 
                <!-- <i class="el-icon-star-on"></i>点赞:{{item.likesCount}} -->
                  <span class="section-relact" v-show="item.replyCount>0">
                    <span class="relact">商家回复：</span>  {{item.resources}}
                </span>
              </div>
             
            </div>
        </section> 
        </li>
      </ul>
    </div></el-tab-pane>
        <el-tab-pane label="好评" name="second"> <div class="comment-detail" >
      <ul>
        <li v-for="item in goodComment" :key="item.id">
           <section class="comment-section" >
            <div class="section-right">
              <img :alt="item.username" :src="item.header">
              <div>{{item.username}}</div>
            </div> 
            <div class="section-left">
              <div class="section-comment">{{item.description}}</div>
              <div class="section-time">评价时间: {{item.createTime | dateFormat}} &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 商品名:  <span class="spuName">{{item.spuName}}&nbsp;&nbsp; &nbsp;</span>商品属性: <span class="spuName">{{item.skuValues}}</span></div>
              <div class="section-count">
                <!-- <i class="el-icon-star-on"></i>点赞:{{item.likesCount}} -->
                <span class="section-relact" v-show="item.replyCount>0">
                <span class="relact">商家回复：</span>  {{item.resources}}
                </span></div>
            </div>
        </section> 
        </li>
      </ul>
    </div></el-tab-pane>
        <el-tab-pane label="差评" name="third"> <div class="comment-detail" >
      <ul>
        <li v-for="item in badComment" :key="item.id">
          <section class="comment-section" >
            <div class="section-left">
              <img :alt="item.username" :src="item.header">
              <div>{{item.username}}</div>
            </div> 
            <div class="section-right">
              <div class="section-comment">{{item.description}}</div>
              <div class="section-time">评价时间: {{item.createTime | dateFormat}} &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;商品名:  <span class="spuName">{{item.spuName}}&nbsp;&nbsp; &nbsp;</span>商品属性: <span class="spuName">{{item.skuValues}}</span></div>
              <div class="section-count" >
                <!-- <i class="el-icon-star-on"></i>点赞:{{item.likesCount}} <i class="el-icon-s-opportunity"></i>  -->
               <span class="section-relact" v-show="item.replyCount>0">
                <span class="relact">商家回复：</span>  {{item.resources}}
              </span></div>
            </div>
            
        </section> 
        </li>
      </ul>
    </div></el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>

<script>
export default {
  name:'Comment',
  data () {
    return {
      spuId:'',
       activeName: 'first',
      commentInfo:[],
      goodComment:[],
      badComment:[],
    };
  },
   // 通过路由获取商品id
  activated() {
    if (this.$route.query.productID != undefined) {
      this.spuId =this.$route.query.productID
       this.getCommentList()
    }
  },
  methods:{
    async getCommentList() {
     const {data:res} = await this.$http.get(`/xuanmall/shopcomment/getComment/${this.spuId}`)
     console.log("商品评论",res)
     if(res.code === 0){
       res.page.list.forEach(async value =>{
         if(value.replyCount){
           const {data:res} = await this.$http.get(`/xuanmall/shopcomment/info/${value.id}`)
          //  console.log(res)
           value.resources =res.shopCommentEntities[0].description
         }
       })
      this.goodComment=[],
      this.badComment=[], 
       this.commentInfo = res.page.list
       this.commentInfo.forEach(item =>{
         if(item.star>=3){
           this.goodComment.push(item)
         }else{
           this.badComment.push(item)
         }
       })
     }
    //  console.log(this.commentInfo)
    //  console.log(this.goodComment)
    //  console.log(this.badComment)
   },
     handleClick(tab, event) {
        console.log(tab, event);
    },
    // 点赞
    async  addGoods(data){
      console.log("我点赞了",data)
    }
  }

}

</script>
<style  lang='less'  scoped>
.comment{
  background-color: rgb(245, 239, 239);;
  box-sizing: border-box;
  width: 1200px;
  padding: 20px;
  h1{
    height: 50px;
    padding: 30px;
    font-weight: 700;
    line-height: 50px;
    font-size: 50px;
  }
  // .comment-grade{
  //   background-color: rgb(218, 212, 212);
  //   padding: 10px;
  //   border: 1px solid rgb(122, 112, 112);
  // }
  .comment-detail{
    li{
      // height: 100px;
      border-bottom: 1px solid rgb(122, 112, 112);
      
      background-color: #fff;
      padding: 20px 0;
      .comment-section{
      .section-right{
          float: right;
          padding: 0 30px;
          border-left: 1px solid  rgb(122, 112, 112);
          img{
            height: 60px;
            width: 60px;
            margin:5px 0;
          }
          width: 200px;
          box-sizing: border-box;
          margin-right: 20px;
          text-align: center;
          div{
            text-overflow: ellipsis;
            overflow: hidden;
            word-break: break-all;
            white-space: nowrap;
            }
        }
      }
      .section-left{
        position: relative;
        .section-comment{
          margin: 10px 0;
          color: rgb(0, 0, 0);
          font-size: 18px;
          padding-left: 50px;
        }
        .section-time{
          color: rgb(83, 77, 77);
           padding-left: 50px;
           margin-top:20px;
        }
        .spuName{
          display: inline-block;
          font-size: 13px;
          margin-right:40px ;
        }
        .section-count{
          margin-top:10px;
          width:800px;
          padding-left: 50px;
          color: rgb(241, 166, 4);
          cursor: pointer;
          .section-relact{
            display: inline-block;
            padding-left: 50px;
            cursor: pointer;
            color: rgb(70, 65, 55);
            padding: 3px;
            margin: 0 30px 0 100px;
            border: 1px solid #ccc;
            .relact{
              color:red;
            }
        }
        }
        
      }
    }
  }
}
</style>